package com.fc.happyteam.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期处理
 * 
 * @author Rocky

 * @date 2016年12月21日 下午12:53:33
 */
public class DateUtils {
	/** 时间格式(yyyy-MM-dd) */
	public final static String DATE_PATTERN = "yyyy-MM-dd";
	/** 时间格式(yyyy-MM-dd HH:mm:ss) */
	public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

    public static final long MILLISECOND_PER_SECOND = 1000L;

	public static String format(Date date) {
        return format(date, DATE_PATTERN);
    }

    public static String format(Date date, String pattern) {
        if(date != null){
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            return df.format(date);
        }
        return null;
    }

    public static int getEpochTimeInSecond(final Date date)
    {
        return (int) (date.getTime() / MILLISECOND_PER_SECOND);
    }

    public static boolean between(Integer s1, Integer s2) {
        int now = getEpochTimeInSecond(new Date());
        return (s1 != null && now >= s1) && (s2 != null && now <= s2);
    }
}
